﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Zocono.WCS.Domain.DomainRepository;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;
using Zocono.WMS.Infrastructure.BaseRepository;

namespace Zocono.WCS.Infrastructure.Repository
{
    public class PlcConnectionStateInfoRepository:BaseRepository<PlcConnectionStateInfo>, IPlcConnectionStateInfoRepository
    {
        public PlcConnectionStateInfoRepository(SqlSugarClient context = null) : base(context)
        {

        }

        public async Task<List<PlcConnectionStateInfoDto>> GetPlcConnectionStateInfoAsync(Expression<Func<PlcConnectionStateInfo, PlcConnectionInfo, bool>> exp)
        {
            List<PlcConnectionStateInfoDto> list = new List<PlcConnectionStateInfoDto>();
            RefAsync<int> totalNumber = 0;
            var result = await Context.Queryable<PlcConnectionStateInfo, PlcConnectionInfo>((a, b) => new JoinQueryInfos(
                JoinType.Inner, a.PlcConnectionID == b.ID))
                .Where(exp)
                .Select((a, b) => new PlcConnectionStateInfoDto
                {
                    ID = a.ID,
                    PlcConnectionID = a.PlcConnectionID,
                    ProgrameCode = a.ProgrameCode,
                    Connected = a.Connected,
                    UpdateTime = a.UpdateTime,
                    PlcConnectionIP = b.IP,
                    PlcCpuType = b.PlcCpuType.ToString(),
                }).ToListAsync();
            return result;
        }
    }
}
